﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Asion.Dapper
{
    public abstract class BaseRepository
    {

        public BaseRepository()
        {
            _db_connection_factory = DapperConfiguration.connection_factory;
        }
        private readonly IDbConnectionFactory _db_connection_factory;




        /// <summary>
        /// get connection
        /// </summary>
        /// <returns></returns>
        internal IDbConnection GetDbConnection<TEntity>()
        {
            var tenantName = TenantMananger.GetTenantsName<TEntity>();
            return _db_connection_factory.CreateConnection(tenantName);
        }

        /// <summary>
        /// get connection by tenants name
        /// </summary>
        /// <returns></returns>
        internal IDbConnection GetDbConnection(string name)
        {

            return _db_connection_factory.CreateConnection(name);
        }
    }
}
